package org.thanos.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.thanos.demo.service.CustomerService;

import java.util.concurrent.CompletableFuture;

@Component
public class AppListener implements ApplicationListener<ApplicationReadyEvent> {

    @Autowired
    private CustomerService customerService;

    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
        CompletableFuture.runAsync(() -> {
            for (; ; ) {
                customerService.insert();
            }
        });
    }
}
